package com.supermap;

import com.supermap.crypto.CryproType;
import com.supermap.server.NettyServer;
import com.supermap.sqlite.SqliteConnection;

import java.io.IOException;
import java.util.Vector;


/**
 * @author liqs
 * @version 1.0
 * @date 2021/04/02 17:58
 */
public class Main {

    //  java -classpath ipfsserver-10.2.1-SNAPSHOT.jar com.supermap.Main
    public static void main(String[] args) throws Exception {

        SqliteConnection.creatSqlite();

        // TODO 后台单独开一个线程进行 ipfs 数据的同步 采用SQLite的方式存储
//        synchronizeIpfsData();
        String cryptoTypeName = CryproType.getRSA();
        // 配置服务端私钥，有就加载，没有就生成
        NettyServer.loadServerPrivFromPath("priv.pem", "pub.pem", cryptoTypeName);
        new NettyServer(cryptoTypeName).bind(50010);
    }

    private static void synchronizeIpfsData() {
        Vector<Thread> threads = new Vector<>();
        threadForCacheIpfs threadForCacheIpfs = new threadForCacheIpfs();
        Thread thread = new Thread(threadForCacheIpfs);
        threads.add(thread);
        thread.start();
    }

    static class threadForCacheIpfs implements Runnable {

        @Override
        public void run() {
            try {
                Utils.synchronizeIpfsData();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }



}
